import 'package:get/get.dart';
import 'package:oli/bean/StatisticsBean.dart';
import 'package:oli/pages/main/home/statisitc/state.dart';

class StatisticLogic extends GetxController {
  final StatisticState state = StatisticState();
  @override
  void onInit() {
    super.onInit();
    state.statistics.addAll([
      StatisticsBean(
        timeRange: '2023年',
        averageFuelConsumption: 10.5,
        averageTripDistance: 27.0,
        averageCostPerKm: 0.85,
        totalMileage: 9000,
        totalCost: 8000.0,
        totalFuel: 1000.0,
        year: '2023年度',
      ),
      StatisticsBean(
        timeRange: '2024年',
        averageFuelConsumption: 10.77,
        averageTripDistance: 27.70,
        averageCostPerKm: 0.90,
        totalMileage: 9446,
        totalCost: 8526.71,
        totalFuel: 1025.19,
        year: '2024年度',
      ),
      StatisticsBean(
        timeRange: '2025年',
        averageFuelConsumption: 11.0,
        averageTripDistance: 28.0,
        averageCostPerKm: 0.95,
        totalMileage: 9800,
        totalCost: 9000.0,
        totalFuel: 1050.0,
        year: '2025年度',
      ),
    ]);
    state.years.addAll(
      state.statistics
          .whereType<StatisticsBean>()
          .toList()
          .map((stat) => stat.year)
          .toSet()
          .toList(),
    );
    state.selectedYear.value = state.years.first;
  }
}
